/**
 * @(#) AbstractDao.java  
 *
 * @author lihg 
 * @version V1.0 2013-10-5  
 *
 * Copyright (C) 2010,2013 , Lihg
 */

/**
 * 
 */
package cn.com.dshome.acquisition.dao;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import cn.com.dshome.acquisition.entity.BaseEntity;

/**
 * 
 * Purpose:基础Dao类
 * 
 * @author lihg
 * @see
 * @since
 */
@Repository
public abstract class AbstractDao<T extends BaseEntity> {
	@Autowired
	private HibernateDao hibernateDao;

	/**
	 * 新增
	 * @param entity
	 * @return
	 */
	public Serializable save(T entity) {
		return hibernateDao.save(entity);
	}

	/**
	 * 修改
	 * @param entity
	 */
	public void update(T entity) {
		hibernateDao.update(entity);
	}

	/**
	 * 新增或不做处理
	 * @param entity
	 * @return
	 */
	public Serializable saveOrDoNothing(T entity){
		return null ;
	}
	
	/**
	 * 查询所有信息
	 * @param clazz
	 * @return
	 */
	public List<T> listAll(Class<T> clazz) {
		return hibernateDao.listAll(clazz);
	}

	/**
	 * 按DetachedCriteria查询信息
	 * @param criteria
	 * @return
	 */
	public List<T> listByDetachedCriteria(DetachedCriteria criteria) {
		return hibernateDao.listByDetachedCriteria(criteria);
	}

	/**
	 * 按HQL查询出所有的信息
	 * @param hql
	 * @param params
	 * @return
	 */
	public List<T> listByHQL(String hql, Map<String, Object> params) {
		return hibernateDao.listByHQL(hql, params);
	}

	/**
	 * 根据ID查询单条记录
	 * @param clazz
	 * @param id
	 * @return
	 */
	public T get(Class<T> clazz, Serializable id) {
		return hibernateDao.get(clazz, id);
	}
}

/**
 * Revision history
 * -------------------------------------------------------------------------
 * 
 * Date Author Note
 * -------------------------------------------------------------------------
 * 2013-10-5 下午02:38:46 lihg 创建版本
 */
